/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/08/01
*/
#ifndef __EDUI_SDL_TEXTURE_H__
#define __EDUI_SDL_TEXTURE_H__

#include "SDL.h"
#include "SDL_image.h"
#include "edui/interface/ITexture.h"

EDUI_NAMESPACE_BEGIN


typedef struct TextureFrame
{
	SDL_Texture* texture;
	int x,y;
	int delay;
} TextureFrame;

class Texture : public ITexture
{
protected:
    Texture();
    virtual ~Texture();
public:
	static Texture* GetInterface();
	virtual void Release();
    static Texture* ToTexture(ITexture* texture);
#ifdef EDUI_TEST_NEW_DELETE
    static int m_newdeleteNum;
    static int _GetNewDeleteNum();
#endif
public:
    virtual bool Create(IRender* render, int w, int h, TextureAccess access, const char* name, int id = -1);
	// if no name,default file
	virtual bool Create(IRender* render, const char* file, const char* name = 0, int id = -1);
	// if no name,default the same as surface
	virtual bool Create(IRender* render, ISurface* surface, const char* name = 0, int id = -1);

	// create use this function, you must Destroy and Release this texture.
	virtual bool Create(SDL_Texture* texture);

    virtual bool IsOK();
	virtual void Destroy();

	//Texture number.
    virtual int GetNum();
    //for gif
    virtual Point GetOffset(int id);
    //for gif
    virtual int GetDelay(int id);
	
	virtual Size GetSize(int id = 0);

	virtual bool SetColorMod(Uint8 r, Uint8 g, Uint8 b, int id = 0);
	virtual Color GetColorMod(int id = 0);
	virtual bool SetAlphaMod(Uint8 alpha, int id = 0);
	virtual Uint8 GetAlphaMod(int id = 0);
	virtual bool SetBlendMode(BlendMode mode, int id = 0);
	virtual BlendMode GetBlendMode(int id = 0);

	virtual void Update(const Rect* rect, const void* pixels, int pitch, int id = 0);
	virtual void UpdateYUV(const Rect* rect,
						const Uint8 *Yplane, int Ypitch,
                        const Uint8 *Uplane, int Upitch,
                        const Uint8 *Vplane, int Vpitch, int id = 0);

	virtual bool Lock(const Rect* rect, void** pixels, int* pitch, int id = 0);
	virtual void Unlock(int id = 0);

public:
	SDL_Texture* GetSDLTexture(int id = 0) const;
protected:
	void _Add(SDL_Texture* texture);
	bool _CeateAndAdd(IRender* render, ISurface* surface);
protected:
    TextureFrame* m_frames;
	int m_num;
};

EDUI_NAMESPACE_END

#endif